home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / demoversionen / upsey / src / main.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  7KB  |  352 lines

  1. /*
  2.  *  GUI Designed by : Will Bow
  3.  */
  4.  
  5. #include <dos/dos.h>
  6. #include <exec/types.h>
  7. #include <exec/libraries.h>
  8. #include <libraries/commodities.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <functions.h>
  12.  
  13. #include <local/libraries/reqtools.h>
  14.  
  15. /*
  16.  *  Application specific include files
  17.  */
  18. #include "ups.h"
  19. #include "main.h"
  20. #include "database.h"
  21. #include "functions.h"
  22.  
  23. static UBYTE *VersTag = "\0$VER: UPSey 1.0pd  (1.07.94)";
  24.  
  25. /* System library bases */
  26. extern struct Library *SysBase, *DOSBase;
  27. struct IntuitionBase *IntuitionBase = NULL;
  28. struct GfxBase *GfxBase = NULL;
  29. struct Library *GadToolsBase = NULL;
  30. struct Library *DiskFontBase = NULL;
  31. struct Library *UtilityBase = NULL;
  32. struct Library *CxBase = NULL;
  33. struct Library *IconBase = NULL;
  34. struct Library *AslBase = NULL;
  35. struct ReqToolsBase *ReqToolsBase = NULL;
  36.  
  37. #define EVT_HOTKEY 1L
  38.  
  39.  
  40. BYTE donotwait = 0;
  41. BYTE cx_popup = 0;
  42. char *cx_popkey = NULL;
  43. char *database = NULL;
  44.  
  45. struct List record_list;
  46.  
  47. struct MsgPort *broker_mp;
  48.  
  49. CxObj *broker, *filter, *sender, *translate;
  50.  
  51. ULONG intuisigflag = 0L, cxsigflag = 0L;
  52.  
  53. struct NewBroker newbroker =
  54. {
  55.   NB_VERSION,
  56.   "UPSey",            /* string to identify this broker */
  57.   " UPSey:  Giftware from BOTH Software",
  58.   " Translates Zip Codes to UPS Zones",
  59.   NBU_UNIQUE | NBU_NOTIFY,    /* Don't want any new commodities
  60.                  * starting with this name.  If someone
  61.                  * tries it, let me know */
  62.   COF_SHOW_HIDE,
  63.   0,
  64.   0,
  65.   0
  66. };
  67.  
  68.  
  69. LONG
  70. ProcessCXMsg (void)
  71. {
  72.   extern struct MsgPort *broker_mp;
  73.   extern CxObj *broker;
  74.  
  75.   CxMsg *msg;
  76.  
  77.   LONG returnvalue = 1L;
  78.  
  79.   while (msg = (CxMsg *) GetMsg (broker_mp))
  80.     {
  81.       ULONG msgid = CxMsgID (msg);
  82.       ULONG msgtype = CxMsgType (msg);
  83.  
  84.       ReplyMsg ((struct Message *) msg);
  85.  
  86.       switch (msgtype)
  87.     {
  88.     case CXM_IEVENT:
  89.  
  90.       switch (msgid)
  91.         {
  92.         case EVT_HOTKEY:
  93.           Project0OpenWindow ();
  94.           break;
  95.  
  96.         default:
  97.           break;
  98.         }
  99.       break;
  100.  
  101.     case CXM_COMMAND:
  102.  
  103.       switch (msgid)
  104.         {
  105.         case CXCMD_APPEAR:
  106.           Project0OpenWindow ();
  107.           break;
  108.  
  109.         case CXCMD_DISAPPEAR:
  110.           Project0CloseWindow ((struct IntuiMessage *) NULL);
  111.           break;
  112.  
  113.         case CXCMD_DISABLE:
  114.           ActivateCxObj (broker, 0L);
  115.           break;
  116.  
  117.         case CXCMD_ENABLE:
  118.           ActivateCxObj (broker, 1L);
  119.           break;
  120.  
  121.         case CXCMD_KILL:
  122.           returnvalue = 0L;
  123.           break;
  124.  
  125.         case CXCMD_UNIQUE:
  126.  
  127.           returnvalue = 0L;
  128.           break;
  129.         default:
  130.           break;
  131.         }
  132.       break;
  133.     default:
  134.       break;
  135.     }
  136.     }
  137.  
  138.   return (returnvalue);
  139. }
  140.  
  141. main (int argc, char **argv)
  142. {
  143.  
  144.   /*  For AmigaDOS 2.xx or later */
  145.   {
  146.     extern struct Library *DOSBase;
  147.  
  148.     if (((struct DosLibrary *) DOSBase)->dl_lib.lib_Version < 37)
  149.       exit (RETURN_ERROR);
  150.   }
  151.  
  152.   {
  153.     char **ttypes;
  154.  
  155.     if (CxBase = OpenLibrary ("commodities.library", 37L))
  156.       {
  157.     if (IconBase = OpenLibrary ("icon.library", 36L))
  158.       {
  159.         if (broker_mp = CreateMsgPort ())
  160.           {
  161.         newbroker.nb_Port = broker_mp;
  162.         cxsigflag = 1L << broker_mp->mp_SigBit;
  163.  
  164.         ttypes = ArgArrayInit (argc, argv);
  165.  
  166.         donotwait = (BYTE) ArgInt (ttypes, "DONOTWAIT", NULL);
  167.  
  168.         newbroker.nb_Pri = (BYTE) ArgInt (ttypes, "CX_PRIORITY", 0);
  169.  
  170.         Project0Top = (UWORD) ArgInt (ttypes, "YPOSITION", 26);
  171.         Project0Left = (UWORD) ArgInt (ttypes, "XPOSITION", 83);
  172.  
  173.         cx_popup = (stricmp ("NO", ArgString (ttypes, "CX_POPUP", "TRUE")) == 0) ? FALSE : TRUE;
  174.  
  175.         cx_popkey = ArgString (ttypes, "CX_POPKEY", "ctrl lalt u");
  176.  
  177.         database = ArgString (ttypes, "DATABASE", NULL);
  178.  
  179.         if (broker = CxBroker (&newbroker, NULL))
  180.           {
  181.             if (filter = CxFilter (cx_popkey))
  182.               {
  183.  
  184.             AttachCxObj (broker, filter);
  185.  
  186.             if (sender = CxSender (broker_mp, EVT_HOTKEY))
  187.               {
  188.                 AttachCxObj (filter, sender);
  189.  
  190.                 if (translate = (CxTranslate (NULL)))
  191.                   {
  192.                 AttachCxObj (filter, translate);
  193.  
  194.                 if (!CxObjError (filter))
  195.                   {
  196.                     UPSey ();
  197.                   }
  198.                   }
  199.               }
  200.               }
  201.  
  202.             DeleteCxObjAll (broker);
  203.           }
  204.  
  205.         DeletePort (broker_mp);
  206.           }
  207.  
  208.         ArgArrayDone ();
  209.         CloseLibrary (IconBase);
  210.       }
  211.     CloseLibrary (CxBase);
  212.       }
  213.   }
  214. }
  215.  
  216.  
  217. int
  218. UPSey (void)
  219. {
  220.  
  221.   /* open the libraries */
  222.   IntuitionBase = (struct IntuitionBase *) OpenLibrary ((UBYTE *) "intuition.library", LIBRARY_MINIMUM);
  223.   GfxBase = (struct GfxBase *) OpenLibrary ((UBYTE *) "graphics.library", LIBRARY_MINIMUM);
  224.   GadToolsBase = OpenLibrary ((UBYTE *) "gadtools.library", LIBRARY_MINIMUM);
  225.   DiskFontBase = OpenLibrary ((UBYTE *) "diskfont.library", LIBRARY_MINIMUM);
  226.   UtilityBase = OpenLibrary ((UBYTE *) "utility.library", LIBRARY_MINIMUM);
  227.   AslBase = OpenLibrary ((UBYTE *) "asl.library", LIBRARY_MINIMUM);
  228.   ReqToolsBase = (struct ReqToolsBase *) OpenLibrary ((UBYTE *) "reqtools.library", LIBRARY_MINIMUM);
  229.  
  230.   if (!IntuitionBase || !GfxBase || !GadToolsBase || !DiskFontBase || !UtilityBase || !AslBase || !ReqToolsBase)
  231.     {
  232.       printf ("oops! Library opening problem!\n");
  233.       goto oops;
  234.     }
  235.  
  236.   if (SetupScreen ())
  237.     {
  238.       printf ("oops! Screen opening problem!\n");
  239.       goto oops;
  240.  
  241.     }
  242.  
  243.   NewList (&record_list);
  244.  
  245.   if (GetRecordList (&record_list, (STRPTR) database))
  246.     {
  247.       /* Our IDCMP signal */
  248.  
  249.       if (cx_popup == TRUE)
  250.     {
  251.       Project0OpenWindow ();
  252.     }
  253.  
  254.       ActivateCxObj (broker, 1L);
  255.  
  256.       while (1)            /* MAIN PROGRAM LOOP */
  257.     {
  258.       ULONG sig_a = intuisigflag;    /* Our Intuition signal */
  259.  
  260.       ULONG sig_b = cxsigflag;    /* Our CX signal */
  261.  
  262.       ULONG sigr = 0L;
  263.  
  264.       /* Wait for something to happen */
  265.  
  266.       sigr = Wait (sig_a | sig_b);
  267.  
  268.       if (sigr & sig_a)    /* Process Intuition messages */
  269.         {
  270.           if (HandleProject0IDCMP () == NULL)
  271.         break;
  272.         }
  273.       else if (sigr & cxsigflag)
  274.         {
  275.           if (ProcessCXMsg () == NULL)
  276.         break;
  277.         }
  278.     }
  279.  
  280.       ActivateCxObj (broker, 0L);
  281.  
  282.       if (Project0Wnd)
  283.     Project0CloseWindow ((struct IntuiMessage *) NULL);
  284.  
  285.       FreeRecordList (&record_list);
  286.  
  287.     }
  288.   else
  289.     {
  290.  
  291.       rtEZRequestTags (" UPSey: FATAL ERROR: Unable to locate database file.\n"
  292.                " Please read UPSey.guide for help\n",
  293.                "Continue",
  294.                NULL,
  295.                NULL,
  296.                RT_ReqPos, (ULONG *) REQPOS_CENTERSCR,
  297.                TAG_END);
  298.  
  299.     }
  300.  
  301.  
  302. oops:
  303.  
  304.   if (Project0Wnd)
  305.     Project0CloseWindow ((struct IntuiMessage *) NULL);
  306.  
  307.   if (Scr)
  308.     CloseDownScreen ();
  309.  
  310.   if (ReqToolsBase)
  311.     {
  312.       CloseLibrary ((struct Library *) ReqToolsBase);
  313.       ReqToolsBase = NULL;
  314.     }
  315.  
  316.   if (AslBase)
  317.     {
  318.       CloseLibrary ((struct Library *) AslBase);
  319.       AslBase = NULL;
  320.     }
  321.  
  322.   if (UtilityBase)
  323.     {
  324.       CloseLibrary ((struct Library *) UtilityBase);
  325.       UtilityBase = NULL;
  326.     }
  327.  
  328.   if (DiskFontBase)
  329.     {
  330.       CloseLibrary ((struct Library *) DiskFontBase);
  331.       DiskFontBase = NULL;
  332.     }
  333.  
  334.   if (GadToolsBase)
  335.     {
  336.       CloseLibrary ((struct Library *) GadToolsBase);
  337.  
  338.     }
  339.  
  340.   if (GfxBase)
  341.     {
  342.       CloseLibrary ((struct Library *) GfxBase);
  343.       GfxBase = NULL;
  344.     }
  345.  
  346.   if (IntuitionBase)
  347.     {
  348.       CloseLibrary ((struct Library *) IntuitionBase);
  349.       IntuitionBase = NULL;
  350.     }
  351. }
  352.